<?php
class AppController extends Controller {

	var $components = array(
		'Auth',
		'Session',
		'RequestHandler', 
		'Email', 
		'DateUtility' => array(
				'offset' => 1,
				'format' => 'Y-m-d'
			)
		);
	var $helpers = array('Html', 'Form', 'Paginator', 'Javascript', 'Time','TimeUtility', 'Session', 'Graph', 'Text');
	var $user = false;
	
	function setUser() {
		if($this->Auth->user()) {
			$this->user = $this->Auth->user();
		} 
		
		$this->set('user', $this->user);
	}
	
	function beforeFilter() {
		$this->setUser();
		$this->Auth->allow('*');
		//Configure::write('Config.language', 'no');
		// Set default cakelayout in admin
		if(isset($this->params['prefix']) and $this->params['prefix'] == 'admin') {
			$this->layout = "admin";
		}
		//$this->layout = "admin";
		
		Configure::write('Workout.viewDateFormat', 'l, d/m/Y');
		Configure::write('Workout.defaultZone', 1);
		Configure::write('Workout.topZone', 5);
		
		// No login on localhost
		if (env('REMOTE_ADDR') != '::1') {
		//$this->Authake->beforeFilter($this);
		}
		//$this->Authake->beforeFilter($this);
		
		App::import("Model", "Settings.Setting");
    	$setting = new Setting;
		$setting->writeSettings();
		
		if($this->RequestHandler->isAjax()) {
			Configure::write ('debug', 0);
		}
		
		return true;
	}
	
	function afterFilter() {
		parent::afterFilter();
	}

}
?>